package com.smartHome.controller;

import com.smartHome.pojo.dto.SceneDto;
import com.smartHome.pojo.entity.Result;
import com.smartHome.pojo.entity.Scene;
import com.smartHome.pojo.entity.SceneDevice;
import com.smartHome.pojo.vo.RoomVO;
import com.smartHome.service.SceneDeviceService;
import com.smartHome.service.SceneService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/scene")
public class SceneController {
    @Autowired
    private SceneService sceneService;
    @Autowired
    private SceneDeviceService sceneDeviceService;

    /**
     * 通过房间Id查询所有场景任务
     * @param roomId
     * @return
     */
    @GetMapping("/getSceneList/{roomId}")
    public Result<List<Scene>> getSceneList(@PathVariable Integer roomId){
        List<Scene> sceneList= sceneService.getSceneList(roomId);
        return Result.success(sceneList);
    }

    /**
     * 通过场景Id获取场景设备列表
     * @param sceneId
     * @return
     */
    @GetMapping("/getSceneDeviceList/{sceneId}")
    public Result<List<SceneDevice>> getSceneDeviceList(@PathVariable Integer sceneId){
        List<SceneDevice> sceneDeviceList= sceneDeviceService.getSceneDeviceList(sceneId);
        return Result.success(sceneDeviceList);
    }

    /**
     * 修改场景状态和定时时间
     * @param scene
     * @return
     */
    @PostMapping("/updateScene")
    public Result updateScene(@RequestBody Scene scene){
        sceneService.updateScene(scene);
        return Result.success();
    }

    /**
     * 执行定时任务更改设备状态
     * @param sceneId
     * @return
     */
    @GetMapping("/implementUpdate/{sceneId}")
    public Result  implementUpdate(@PathVariable Integer sceneId){
        sceneService.implementUpdate(sceneId);
        return Result.success();
    }

    /**
     * 添加场景定时任务
     * @param scene
     * @return
     */
    @PostMapping("/addScene")
    public Result addScene(@RequestBody Scene scene){
        sceneService.addScene(scene);
        return Result.success();
    }

    /**
     * 删除场景任务
     * @param sceneId
     * @return
     */
    @GetMapping("/deleteScene/{sceneId}")
    public Result deleteScene(@PathVariable Integer sceneId){
        sceneService.deleteScene(sceneId);
        return Result.success();
    }

    @GetMapping("/getSceneNumber")
    public Result<List<Scene>> getSceneNumber(){
        List<Scene> sceneList= sceneService.getSceneNumber();
        return Result.success(sceneList);
    }
}
